home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xless / xless141.z / xless141 / xless-1.4.1 / help.c < prev    next >
C/C++ Source or Header  |  1993-05-05  |  4KB  |  140 lines

  1. /*
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of M.I.T. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  M.I.T. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  16.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  18.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  19.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * Author: Carlo Lisa
  22.  *       MIT Project Athena
  23.  *
  24.  * $Header: /usr/sww/share/src/X11R5/local/clients/xless-1.4/RCS/help.c,v 1.11 1993/02/26 02:09:54 dglo Exp dglo $
  25.  */
  26.  
  27. #include "xless.h"
  28. #include "XLessHelp.icon"
  29.  
  30. static Widget createHelp ARGS((void));
  31. static void PopdownHelp ARGS((Widget, XtPointer, XtPointer));
  32.  
  33. /*    Function Name: CreateHelp.
  34.  *    Description: This function creates the help widget so that it will be
  35.  *                 ready to be displayed.
  36.  *    Arguments:
  37.  *    Returns: the help widget
  38.  */
  39.  
  40. static Widget
  41. createHelp()
  42. {
  43.   extern Widget toplevel;
  44.   FILE *help_file;
  45.   Cardinal i;
  46.   Arg args[4];
  47.   const char *help_page;
  48.   Pixmap helpicon;
  49.   Widget base, pane, helptext, button;
  50.   XtCallbackRec callback[2];
  51.   XtAccelerators accel;
  52.   const String quitstr = "#override <Key>Q: set() notify() unset()\n";
  53.  
  54.   /* try to open the help file */
  55.   if ((help_file = fopen(resources.help_file, "r")) == NULL) {
  56.     CouldntOpen(toplevel, resources.help_file);
  57.     return 0;
  58.   }
  59.   help_page = InitData(help_file);
  60.  
  61.   /* create a new application shell */
  62.   i = 0;
  63.   helpicon = XCreateBitmapFromData(disp, XRootWindow(disp, 0), XLessHelp_bits,
  64.                    XLessHelp_width, XLessHelp_height);
  65.   XtSetArg(args[i], XtNiconPixmap, helpicon); i++;
  66.   XtSetArg(args[i], XtNiconName, "xless: help"); i++;
  67.   XtSetArg(args[i], XtNallowShellResize, TRUE); i++;
  68.   base = XtAppCreateShell("help", XLESS_CLASS, applicationShellWidgetClass,
  69.               disp, args, i);
  70.  
  71.   pane = XtCreateManagedWidget("help_pane", panedWidgetClass, base, NULL, 0);
  72.  
  73.   helptext = MakeText(pane, help_page);
  74.  
  75.   /* set up Done button callback array */
  76.   callback[0].callback = PopdownHelp;
  77.   callback[0].closure = (XtPointer)base;
  78.   callback[1].callback = NULL;
  79.   callback[1].closure = (XtPointer)NULL;
  80.  
  81.   /* set up Done button accelerator */
  82.   accel = XtParseAcceleratorTable(quitstr);
  83.  
  84.   /* create Done button */
  85.   i = 0;
  86.   XtSetArg(args[i], XtNfont, buttonfont); i++;
  87.   XtSetArg(args[i], XtNlabel, "Done With Help"); i++;
  88.   XtSetArg(args[i], XtNcallback, callback); i++;
  89.   XtSetArg(args[i], XtNaccelerators, accel); i++;
  90.   button = XtCreateManagedWidget("help_quit", commandWidgetClass, pane,
  91.                    args, i);
  92.   XtInstallAccelerators(helptext, button);
  93.  
  94.   XtRealizeWidget(base);
  95.  
  96.   return(base);
  97. }
  98.  
  99. /*    Function Name: PopdownHelp
  100.  *    Description: This function pops down the help widget.
  101.  *    Arguments: w - the widget we are calling back from.
  102.  *               number - (closure) the number to switch on.
  103.  *               junk - (call data) not used.
  104.  *    Returns: none.
  105.  */
  106.  
  107. /* ARGSUSED */
  108.  
  109. static void
  110. PopdownHelp(w, help_widget, junk)
  111. Widget w;
  112. XtPointer help_widget, junk;
  113. {
  114.   XtPopdown((Widget )help_widget);
  115. }
  116.  
  117. /*    Function Name: PopupHelp
  118.  *    Description: This function pops up the help widget, unless no
  119.  *                 help could be found.
  120.  *    Arguments: w - the widget we are calling back from.
  121.  *               number - (closure) the number to switch on.
  122.  *               junk - (call data) not used.
  123.  *    Returns: none.
  124.  */
  125.  
  126. /* ARGSUSED */
  127.  
  128. void
  129. PopupHelp(w, number, junk)
  130. Widget w;
  131. XtPointer number, junk;
  132. {
  133.   static Widget help_widget = 0;
  134.  
  135.   if (!help_widget)
  136.     help_widget = createHelp();
  137.   if (help_widget)
  138.     XtPopup(help_widget, XtGrabNone);
  139. }
  140.